package com.example.book.crawler.controller;

import com.example.book.base.BaseController;
import com.example.book.base.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.example.book.crawler.entity.CrawlerContent;
import com.example.book.crawler.service.CrawlerContentService;


/**
 * @author hcj
 * @date 2019-11-01 22:25:05
 */
@Controller
@RequestMapping(value = "/crawlerContent")
public class CrawlerContentController extends BaseController {

    @Autowired
    private CrawlerContentService crawlerContentService;

    @ModelAttribute
    public CrawlerContent get(@RequestParam(required = false) String id) {
        if (StringUtils.isNotBlank(id)) {
            CrawlerContent crawlerContent = new CrawlerContent();
            crawlerContent.setId(id);
            return crawlerContentService.get(crawlerContent);
        } else {
            return new CrawlerContent();
        }
    }

    @RequestMapping(value = "/get")
    @ResponseBody
    public CrawlerContent getById(CrawlerContent crawlerContent) {
        return crawlerContent;
    }

    @RequestMapping(value = "/list")
    public String list(CrawlerContent crawlerContent) {
        return "crawlerContent";
    }

    @RequestMapping(value = "/info")
    @ResponseBody
    public List<CrawlerContent> info(CrawlerContent crawlerContent) {
        return crawlerContentService.findList(crawlerContent);
    }


    @RequestMapping(value = "/findPage")
    @ResponseBody
    public PageInfo<CrawlerContent> findPage(CrawlerContent crawlerContent) {
        return crawlerContentService.findPage(crawlerContent);
    }

    @RequestMapping(value = "/save")
    @ResponseBody
    public Result save(CrawlerContent crawlerContent) {
        crawlerContentService.save(crawlerContent);
        return Result.success("保存成功");
    }

    @RequestMapping(value = "/logicalDeletion", method = RequestMethod.POST)
    @ResponseBody
    public Result logicalDeletion(@RequestParam("id") String id) {
        crawlerContentService.logicalDeletion(id);
        return Result.success();
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@RequestParam("ids") String[] ids) {
        crawlerContentService.delete(ids);
        return Result.success();
    }

}